package com.service.impl;

import com.entity.PageBean;
import com.entity.PurOrder;
import com.exception.UnpaidStorageException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.PurInvoiceMapper;
import com.mapper.PurPayMapper;
import com.service.PurInvoiceService;
import com.service.PurPayService;
import com.vo.PurOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PurInvoiceServiceImpl implements PurInvoiceService {
    @Autowired
    private PurInvoiceMapper purInvoiceMapper;


    @Override
    public PageBean<PurOrder> getInvoiceList(Integer pageIndex, Integer pageSize, PurOrderVO purOrderVO) {
        PageHelper.startPage(pageIndex, pageSize);
        List<PurOrder> list= purInvoiceMapper.selectInvoiceList(purOrderVO);
        PageInfo<PurOrder> pageInfo = new PageInfo<>(list);
        PageBean<PurOrder> pageBean = new PageBean<>(
                pageIndex,//第几页
                pageSize,//每页显示的条数
                pageInfo.getPages(),//总页数
                (int)pageInfo.getTotal(),//数据总条数
                pageInfo.getList()//当前页的数据集合
        );
        return pageBean;
    }

    @Override
    public boolean getPaystatusByoid(int oid) {
        return purInvoiceMapper.selectPaystatusByoid(oid) != null;
    }


    @Override
    public void updateInvoiceList(PurOrder purOrder) {
        if(getPaystatusByoid(purOrder.getOid())){
            throw new UnpaidStorageException("该商品处于未付款状态，不能进行开发票操作");
        }
        purInvoiceMapper.updateInvoiceList(purOrder);
    }


}
